import React, { Component } from "react";
import "./xhdLoanResult.scss";
import { connect } from "react-redux";
import XFButton from "@/xfCompontent/xfButton/xfButton";
import sumitSuccess from "@/images/imageXHF/sumitSuccess.png";
import MainLayout from "@/component/mainLayout/mainLayout";
import yhTools from "@/tools/yh";
import { InterfaceG } from "@config/Config";
import Banner from "@/views/viewCommon/Banner";
export class LoanResult extends Component {
	constructor(props) {
		super(props);
		this.state = {
			btnText: "返回首页",
			isShowModal: false,
			bannerList: []
		};

		this.getStateProps();
	}
	getStateProps() {
		if (this.props.location.state) {
			this.isMoreFive = this.props.location.state.isMoreFive;
			this.message = this.props.location.state.message;
		}
	}
	componentDidMount() {
		this.getBannerListByPageType();
	}
	btnFn() {
		this.props.history.push("/xhdHome");
	}
	handleModal() {
		this.setState({
			isShowModal: true
		});
	}
	cancleModal() {
		this.setState({
			isShowModal: false
		});
	}
	//获取banner
	getBannerListByPageType = async () => {
		const params = {
			url: InterfaceG.getBannerListByPageType,
			params: {
				pageType: "XHD_BORROW_RESULT_PAGE"
			},
			_alertShow: false
		};
		try {
			const { code, data } = await yhTools.request(params);
			if (code == "0") {
				const type = this.isMoreFive
					? "XHD_BORROW_RESULT_GT_5_PAGE"
					: "XHD_BORROW_RESULT_LT_5_PAGE";
				if (Array.isArray(data)) {
					const item = data.find(item => item.bannerType === type);
					if (item) {
						if (Array.isArray(item.indexServerDtos)) {
							this.setState({
								bannerList: item.indexServerDtos
							});
						}
					}
				}
			}
		} catch (error) {
			console.log(error);
		}
	};
	gotoOpened() {}

	handleModalBtn() {
		this.setState({
			isShowModal: false
		});
	}
	//goBackPath
	render() {
		const { btnText = "", bannerList } = this.state;
		let _pageParams = {
			header: {
				title: "借款结果",
				goBackPath: "/xhdHome"
			},
			history: this.props.history,
			cacheLifecycles: this.props.cacheLifecycles
		};
		const btnStyle = {
			height: "1rem",
			width: "3.78rem",
			borderRadius: ".5rem"
		};
		return (
			<MainLayout pageParams={_pageParams}>
				<div className="xhd_loan_result">
					<div className="openFail-box">
						<img src={sumitSuccess} />
						<h3>审核中</h3>
						<p>{this.message}</p>
					</div>
					<XFButton
						btText={btnText}
						btnStyle={btnStyle}
						handleBtn={this.btnFn.bind(this)}
					/>
					{bannerList.length > 0 && (
						<div className="xhd-loan-result-banner">
							<h1>更多金融服务</h1>
							<Banner bannerList={bannerList} history={this.props.history} />
						</div>
					)}
				</div>
			</MainLayout>
		);
	}
}

function mapStateToProps(state) {
	return state;
}

function mapDispatchToProps() {
	return {};
}

const LoanResultPage = connect(mapStateToProps, mapDispatchToProps)(LoanResult);
export default LoanResultPage;
